<?php

namespace common\models\ad;

use Yii;
use yii\behaviors\TimestampBehavior;
use yii\behaviors\BlameableBehavior;
use yii\behaviors\AttributeBehavior;
use yii\db\Expression;
use yii\db\ActiveRecord;

/**
 * This is the model class for table "ad".
 *
 * @property int $id
 * @property string $category 分类
 * @property string $banner BANNER图
 * @property string $title 推广标题
 * @property string $link 链接地址
 * @property string $sdk_version 版本要求: 0-全部
 * @property string $valid_from 起始有效期
 * @property string $valid_to 结束有效期
 * @property string $note 备注说明
 * @property int $created_by 操作人
 * @property int $update_by 最后操作人
 * @property string $created 操作时间
 * @property string $updated 更新时间
 * @property int $status 状态：0-保存, 1-上线, 2-下线
 */
class Brand extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'brand';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['category'], 'string'],
            [['valid_from', 'valid_to', 'created', 'updated'], 'safe'],
            [['banner', 'link', 'valid_range'], 'required'],
            [['created_by', 'updated_by', 'status'], 'integer'],
            [['banner', 'note'], 'string', 'max' => 255],
            [['title', 'link'], 'string', 'max' => 100],
            [['sdk_version'], 'string', 'max' => 50],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'category' => 'Category',
            'banner' => 'BANNER图',
            'title' => '标题',
            'link' => '跳转链接',
            'sdk_version' => '版本要求',
            'valid_from' => '有效期',
            'valid_to' => '有效期',
            'valid_range' => '有效期',
            'note' => '备注',
            'created_by' => '操作人',
            'updated_by' => '最后操作人',
            'created' => 'Created',
            'updated' => 'Updated',
            'status' => '状态',
        ];
    }

    /**
     * @inheritdoc
     */
    public function behaviors()
    {
        return [
            [
                'class' => TimestampBehavior::className(),
                'createdAtAttribute' => 'created',
                'updatedAtAttribute' => null,
                'value' => new Expression('NOW()'),
            ],
            [
                'class' => BlameableBehavior::className(),
                'createdByAttribute' => 'created_by',
                'updatedByAttribute' => 'updated_by',
            ],
        ];
    }
}
